//
//  MineHeaderView.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/7.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "MineHeaderView.h"

#define JudgeLogInUI ([ReadLoginData readLoginData].allKeys.count == 0)||([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"0"])||([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"1"])

@interface MineHeaderView()

@end

@implementation MineHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI
{
    self.backgroundColor = DEFAULT_COLOR;
    
       //头像部分
    UIView *HeadView = [[UIView alloc] init];
    HeadView.backgroundColor = DEFAULT_COLOR;
    [self addSubview:HeadView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mineHeaderDidClick)];
    [HeadView addGestureRecognizer:tap];
    
    UIImageView *headImg = [[UIImageView alloc] init];
    headImg.layer.cornerRadius = self.Height/6;
    headImg.layer.masksToBounds = YES;
    [HeadView addSubview:headImg];
    
    if (JudgeLogInData) {
        headImg.image = [UIImage imageNamed:@"headgao.jpg"];
    } else {
        headImg.backgroundColor = [UIColor blueColor];
    }
    
    
    
    UILabel *headLabel = [[UILabel alloc] init];
    [HeadView addSubview:headLabel];
    headLabel.textColor = [UIColor whiteColor];
    headLabel.font = [UIFont systemFontOfSize:15];
    
    if (JudgeLogInData) {
        headLabel.text = USERNAME;
    } else {
        headLabel.text = @"登录 / 注册";
    }
    
    //设置按钮
    UIButton *setupBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:setupBtn];
    [setupBtn setImage:[UIImage imageNamed:@"icon_setup"] forState:UIControlStateNormal];
    [setupBtn addTarget:self action:@selector(setupBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [HeadView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY).offset(self.Height/6);
        make.height.mas_equalTo(HEIGHT/8);
        make.width.mas_equalTo(WIDTH/3);
    }];
    
    [headImg mas_makeConstraints:^(MASConstraintMaker *make) {
    
        make.top.equalTo(HeadView.mas_top).offset(5);
        make.centerX.equalTo(HeadView.mas_centerX);
        make.height.mas_equalTo(self.Height/3);
        make.width.mas_equalTo(self.Height/3);
    }];
    
    [headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(headImg.mas_bottom).offset(10);
        make.centerX.mas_equalTo(HeadView.mas_centerX);
        
        
    }];
    
    
    [setupBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.mas_right).offset(-15);
        make.top.equalTo(self.mas_top).with.offset(30);
        
    }];
    
    
    
}

//手势触发代理
- (void)mineHeaderDidClick
{
    if ([self.delegate respondsToSelector:@selector(mineHeaderDidClick)]) {
        [self.delegate mineHeaderDidClick];
    }
}

//设置键   
- (void)setupBtnDidClick:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(mineHeaderSetupDidClick)]) {
        [self.delegate mineHeaderSetupDidClick];
    }
}



@end
